﻿package mortal.game.view.palyer.item
{
    import baseEngine.system.*;
    import com.mui.controls.*;
    import flash.events.*;
    import flash.geom.*;
    import frEngine.pools.*;
    import frEngine.primitives.object2d.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.window3d.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.scene3D.player.entity.*;
    import mortal.game.scene3D.player.info.*;
    import mortal.game.view.common.*;
    import mortal.game.view.copy.QuestionCopy.data.*;
    import mortal.game.view.signUp.sevenDayLogin.item.*;
    import mortal.mvc.core.*;

    public class RoleHalidomPanel extends GSprite
    {
        private var _hImg2D:Img2D;
        private var _hIm:GImageBitmap;
        public var rect3d:Rect3DObject;
        private var _cellArr:Array;
        private var _isLoad:Boolean = false;
        private var _halidomMod:UserModelPlayer;
        private var _visib:Boolean = true;
        public static var posArr:Array = [new Point(213 - 5, 130 - 32), new Point(46 - 5, 163 - 32), new Point(355 - 5, 183 - 32), new Point(92 - 5, 255 - 32), new Point(322 - 5, 281 - 32), new Point(59 - 5, 373 - 32), new Point(382 - 5, 362 - 32), new Point(320 - 5, 452 - 32)];

        public function RoleHalidomPanel()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._isLoad = false;
            this._hIm = UIFactory.gImageBitmap("", 0, -28, null, this.onResLoad);
            return;
        }// end function

        public function init3DMd(param1:Rect3DObject) : void
        {
            this.rect3d = param1;
            var _loc_2:* = Cache.instance.role.roleEntityInfo;
            if (this._halidomMod == null)
            {
                this._halidomMod = FrObjectPool.getObject(UserModelPlayer, this);
                this._halidomMod.updateInfo(_loc_2.entityInfo.career, _loc_2.entityInfo.sex, _loc_2.clothes, 0, _loc_2.hair, 0, _loc_2.entityInfo.VIP);
                this._halidomMod.scaleAll = 2.2;
                this._halidomMod.setRenderList(this.rect3d.renderList);
                this._halidomMod.useLight();
                this._halidomMod.rotationY = 0;
                this.rect3d.addObject3d(this._halidomMod, 250, 450);
                this._halidomMod.removedFromScene();
                this._hIm.imgUrl = ImagesConst.RoleHalidomBg;
            }
            this._halidomMod.updateInfo(_loc_2.entityInfo.career, _loc_2.entityInfo.sex, _loc_2.clothes, 0, _loc_2.hair, 0, _loc_2.entityInfo.VIP);
            return;
        }// end function

        private function onResLoad() : void
        {
            if (isDisposed || this.rect3d == null || this._isLoad == true)
            {
                return;
            }
            this._isLoad = true;
            if (this.rect3d && this._hImg2D)
            {
                this.rect3d.removeImg(this._hImg2D);
                this._hImg2D.dispose();
                this._hImg2D = null;
            }
            this._hImg2D = new Img2D(null, this._hIm.bitmapData, new Rectangle(0, 0, 490, 546), true);
            this._hImg2D.x = 0;
            this._hImg2D.y = 0;
            this.rect3d.addImg(this._hImg2D);
            this.genCells();
            this.updateAllEquip();
            this.visible = this._visib;
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._isLoad = false;
            this._visib = false;
            if (this.rect3d && this._hImg2D)
            {
                this.rect3d.removeImg(this._hImg2D);
                this._hImg2D.dispose();
                this._hImg2D = null;
            }
            if (this.rect3d)
            {
                this.rect3d.disposeObj3d(this._halidomMod);
                this._halidomMod = null;
            }
            this._hIm.dispose(param1);
            this._hIm = null;
            this.clearCells();
            this.rect3d = null;
            super.disposeImpl(param1);
            return;
        }// end function

        private function genCells() : void
        {
            var _loc_2:RoleHalidomCell = null;
            this._cellArr = [];
            var _loc_1:int = 0;
            while (_loc_1 < 8)
            {
                
                _loc_2 = UIFactory.getUICompoment(RoleHalidomCell);
                _loc_2.rect3d = this.rect3d;
                _loc_2.pos = posArr[_loc_1];
                _loc_2.updateName(_loc_1);
                this.addChild(_loc_2);
                this._cellArr.push(_loc_2);
                _loc_2.toolP.configEventListener(MouseEvent.DOUBLE_CLICK, this.doubleCkickHandler);
                _loc_1++;
            }
            return;
        }// end function

        private function doubleCkickHandler(event:MouseEvent) : void
        {
            var _loc_2:* = event.currentTarget as HideAreaSp;
            var _loc_3:* = _loc_2.parent as RoleHalidomCell;
            if (_loc_3.item.itemData && _loc_3.item.itemData.serverData)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.GetOffEquip, _loc_3.item.itemData));
            }
            return;
        }// end function

        private function clearCells() : void
        {
            var _loc_2:RoleHalidomCell = null;
            if (this._cellArr == null)
            {
                return;
            }
            var _loc_1:int = 0;
            while (_loc_1 < this._cellArr.length)
            {
                
                _loc_2 = this._cellArr[_loc_1];
                _loc_2.dispose();
                _loc_1++;
            }
            this._cellArr = null;
            return;
        }// end function

        private function updateAllEquip() : void
        {
            var _loc_1:* = this._cellArr.length;
            var _loc_2:int = 0;
            while (_loc_2 < _loc_1)
            {
                
                this.updateEquipByType(_loc_2);
                _loc_2++;
            }
            return;
        }// end function

        public function updateEquipByType(param1:int) : void
        {
            var _loc_5:int = 0;
            if (param1 < 0 || param1 > this._cellArr.length)
            {
                return;
            }
            var _loc_2:* = mappingTypeToIndex(param1);
            var _loc_3:* = this._cellArr[_loc_2];
            var _loc_4:* = Cache.instance.pack.halidomBag.getEquipByType(param1);
            _loc_3.clearCell();
            if (_loc_4)
            {
                _loc_3.item.itemData = _loc_4;
                _loc_3.updateInfo(param1);
                _loc_3.colorScreen = false;
                _loc_3.item.buttonMode = true;
            }
            else
            {
                _loc_5 = mappingTypeToItemCode(param1);
                _loc_4 = new ItemData(_loc_5);
                _loc_3.item.itemData = _loc_4;
                _loc_3.updateInfo(param1);
                _loc_3.colorScreen = true;
                _loc_3.item.buttonMode = false;
            }
            return;
        }// end function

        override public function set visible(param1:Boolean) : void
        {
            var _loc_2:int = 0;
            var _loc_3:RoleHalidomCell = null;
            super.visible = param1;
            this._visib = param1;
            if (this._isLoad == false)
            {
                return;
            }
            if (this._hImg2D == null)
            {
                return;
            }
            if (param1)
            {
                if (this._hImg2D.scene == null)
                {
                    this._hImg2D.addedToScene(Global3D.scene);
                }
                this._halidomMod.addedToScene(Global3D.scene);
            }
            else
            {
                this._halidomMod.removedFromScene();
            }
            if (this._cellArr)
            {
                _loc_2 = 0;
                while (_loc_2 < this._cellArr.length)
                {
                    
                    _loc_3 = this._cellArr[_loc_2];
                    _loc_3.visible = param1;
                    _loc_2++;
                }
            }
            return;
        }// end function

        public static function mappingTypeToIndex(param1:int) : int
        {
            var _loc_2:int = 0;
            switch(param1)
            {
                case 0:
                {
                    _loc_2 = 6;
                    break;
                }
                case 1:
                {
                    _loc_2 = 7;
                    break;
                }
                case 2:
                {
                    _loc_2 = 0;
                    break;
                }
                case 3:
                {
                    _loc_2 = 1;
                    break;
                }
                case 4:
                {
                    _loc_2 = 3;
                    break;
                }
                case 5:
                {
                    _loc_2 = 5;
                    break;
                }
                case 6:
                {
                    _loc_2 = 2;
                    break;
                }
                case 7:
                {
                    _loc_2 = 4;
                    break;
                }
                default:
                {
                    break;
                }
            }
            return _loc_2;
        }// end function

        public static function mappingTypeToItemCode(param1:int) : int
        {
            var _loc_2:int = 0;
            switch(param1)
            {
                case 0:
                {
                    _loc_2 = 310000000;
                    break;
                }
                case 1:
                {
                    _loc_2 = 310011000;
                    break;
                }
                case 2:
                {
                    _loc_2 = 310020000;
                    break;
                }
                case 3:
                {
                    _loc_2 = 310030000;
                    break;
                }
                case 4:
                {
                    _loc_2 = 310041000;
                    break;
                }
                case 5:
                {
                    _loc_2 = 310051000;
                    break;
                }
                case 6:
                {
                    _loc_2 = 310061000;
                    break;
                }
                case 7:
                {
                    _loc_2 = 310071000;
                    break;
                }
                default:
                {
                    break;
                }
            }
            return _loc_2;
        }// end function

        public static function levelEnougth() : Boolean
        {
            return LevelCheckUtil.isLevelEnougth(60);
        }// end function

    }
}
